/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.entityTable;
import sql.AConnection;

/**
 *
 * @author aragon
 */
public class Local extends AConnection implements entityTable<Local>{
    private String idLocal;
    private String localNam;

    public Local() {
    }

    public Local(String idLocal, String localNam) {
        this.idLocal = idLocal;
        this.localNam = localNam;
    }


    public boolean select() {
        try {
            String query = "SELECT idKhu,TenKhu FROM khuvuc WHERE idKhu=? and AnHien=1";
            Connection connection = getConnection();
            PreparedStatement ps = connection.prepareStatement(query);
            ps.setString(1, getIdLocal());
            ResultSet rs= ps.executeQuery();
            if(rs.next()){
            setLocalNam(rs.getString("TenKhu"));
             return true;
            }else{
                return false;
            }
        } catch (SQLException ex) {
            return false;
        }

    }

    public ResultSet selectDB() {
        try {
            String query = "SELECT idKhu,TenKhu FROM khuvuc WHERE AnHien=1";
            Connection connection = getConnection();
            Statement s = connection.createStatement();
            ResultSet rs=s.executeQuery(query);
            return rs;
        } catch (SQLException ex) {
            return null;
        }

    }

    public boolean insert() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean update() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean remove() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getIdLocal() {
        return idLocal;
    }

    public void setIdLocal(String idLocal) {
        this.idLocal = idLocal;
    }

    public String getLocalNam() {
        return localNam;
    }

    public void setLocalNam(String localNam) {
        this.localNam = localNam;
    }


}
